package cn.ronghuanet.base.listener;

import cn.ronghuanet.base.service.IAutoScanPermissionService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener  //把当前的类交给springIOC容器
public class InitPermissionListener implements ServletContextListener {

    @Autowired
    private IAutoScanPermissionService autoScanPermissionService;
    /*
        在容器初始化的时候执行
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("------------------容器初始化开始----------------------");
        autoScanPermissionService.scan();
        System.out.println("------------------容器初始化结束----------------------");
    }

    /*
        在容器销毁的时候执行
     */
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("------------------容器销毁执行----------------------");
    }
}
